// pages/publish/publish.js
const {post} = require('../../utils/http') 

Page({

  /**
   * 页面的初始数据
   */
  //address，latitude，longitude，message，contact，type（sell，buy），openid
  data: {
    address:"点击选择，要勾选哦~",
    latitude:"",
    longitude:"",
    message:"",
    contact:"",
    type:"buy",
    issubmit:false,
    issuccess:null
  },
  chooseLocation(){
    wx.chooseLocation({
      complete: (res) => {
        console.log(res)
        this.setData({
          address:res.address,
          longitude:res.longitude,
          latitude:res.latitude
        })
      },
    })
  },

  typechange(e){
    this.setData({
      type:e.detail.value
    })
  }

  ,
  inputMessage(e){
      this.setData({
        message:e.detail.value
      })
  },

  inputContact(e){
    this.setData({
      contact:e.detail.value
    })
},

async handleSubmit(){
  console.log('submit')
  if(this.data.address==="点击选择，要勾选哦~"){
    wx.showToast({
      title: '地址不能为空',
      icon: 'loading',
      duration: 2000
    })
    return;
  }

  if(!this.data.message){
    wx.showToast({
      title: '说明不能为空',
      icon: 'loading',
      duration: 2000
    })
    return;
  }

  if(!this.data.contact){
    wx.showToast({
      title: '联系方式不能为空',
      icon: 'loading',
      duration: 2000
    })
    return;
  }

 



  let params = {
    address:this.data.address,
    latitude:this.data.latitude,
    longitude:this.data.longitude,
    message:this.data.message,
    contact:this.data.contact,
    type:this.data.type
  }
  this.setData({
    issubmit:true
  })
 let result = await post('/index.php/trade/add_item',params)
 console.log(result)
 this.setData({
    issuccess:result.ret
 })
},

republish(){
  this.setData({
    issubmit:false,
    issuccess:null
  })
}



  
})